package com.tong.cloud.example.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

@Service
public class QueryGrantTypeService {
    @Autowired
    private GrantTypeService grantTypeService;
    private Map<String, Function<Void, String>> grantTypeMap = new HashMap<>();

    @PostConstruct
    public void dispatcherInit() {
        grantTypeMap.put("红包", resourceId -> grantTypeService.redPaper());
        grantTypeMap.put("购物卷", resourceId -> grantTypeService.shopping());
        grantTypeMap.put("qq会员", resourceId -> grantTypeService.QQVip());
    }


    public String getResult(String resourceType) {
        Function<Void, String> result = grantTypeMap.get(resourceType);
        if (result != null) {
            return result.apply(null);
        }
        return "查询不到该优惠卷发放方式";
    }

}
